//
//  UIButton+Extension.swift
//  新浪微博
//
//  Created by 朱玉龙 on 9/22/16.
//  Copyright © 2016 朱玉龙. All rights reserved.
//

import UIKit
extension UIBarButtonItem {
    
    convenience init(title:String = "", imageName:String?,target: Any?, action: Selector) {

        let button = UIButton()
        
        if imageName != nil {
            
            button.setImage(UIImage.init(named: imageName! ), for: .normal)
            
            button.setImage(UIImage.init(named:(imageName! + "_highlighted"))?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), for: .highlighted)
            
        }
        
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        button .setTitle(title, for: .normal)
        
        button.setTitleColor(UIColor.darkGray, for: .normal)
        
        button.setTitleColor(UIColor.orange, for: .highlighted)
        
        button.sizeToFit()
        
        button .addTarget(target, action: action, for: .touchUpInside)
        
        self.init()
        
        self.customView = button
    }
}
